package com.neu.neumall.order.web;

import com.alipay.api.AlipayApiException;
import com.neu.neumall.order.config.AlipayTemplate;
import com.neu.neumall.order.service.OrderService;
import com.neu.neumall.order.vo.PayVo;
import lombok.SneakyThrows;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;

@Controller
public class PayController {

    @Resource
    AlipayTemplate alipayTemplate;

    @Resource
    OrderService orderService;


    /**
     *  支付宝支付处理接口
     *
     * @param orderSn
     * @return
     */
    @SneakyThrows
    @ResponseBody
    @GetMapping(value = "/payOrder",produces = "text/html")
    public String payOrder(@RequestParam("orderSn") String orderSn ) throws AlipayApiException {

        PayVo payVo = orderService.getOrderPay(orderSn);
        String res = alipayTemplate.pay(payVo);
        return res;
    }


}
